Skip to content

Implement MigratableKVStore for all KV Stores#945

Open
benthecarman wants to merge 6 commits into
lightningdevkit:mainfrom
benthecarman:migrate-dbs
Open

Implement MigratableKVStore for all KV Stores#945
benthecarman wants to merge 6 commits into
lightningdevkit:mainfrom
benthecarman:migrate-dbs

Conversation

@benthecarman

Copy link
Copy Markdown
Contributor

Pulled out of #915

These were unimplemented for our kv stores. Useful if the user wants to migrate to a different database and also in tests so we don't have to re-init and setup a node.

@benthecarman benthecarman added this to the 0.8 milestone Jun 23, 2026
@benthecarman benthecarman requested a review from tnull June 23, 2026 19:53
@ldk-reviews-bot

ldk-reviews-bot commented Jun 23, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase now that #947 landed to get CI to pass.

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, first pass.

Would be cool to add a commit that does a full end-to-end test of migration. I.e., pick a random backend, setup a node with it, open a channel to another node, send some payments, then drop everything and migrate to a random new backend, then ensure the node is still fully functional.

Comment thread src/io/sqlite_store/mod.rs Outdated
Comment thread src/io/vss_store.rs Outdated
Comment thread src/io/vss_store.rs
&& secondary_namespace.is_empty()
&& key == VSS_SCHEMA_VERSION_KEY
{
continue;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we should attempt to always migrate to the latest schema version, allowing nodes to upgrade?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are just listing all keys so we need to support both. The actual migration will just do whatever happens on .write(). Assuming it'll be a fresh VSS store it should persist as the latest schema version

https://github.com/lightningdevkit/rust-lightning/blob/9df5c9dc458fecd91c5018150dd2cec1e4ff04c3/lightning/src/util/persist.rs#L679C10-L679C37

Comment thread src/io/in_memory_store.rs Outdated

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need another rebase after #952 lands.

benthecarman and others added 6 commits June 26, 2026 03:59
This was unimplemented for the sqlite kv store. Useful if the user
wants to migrate to a different database and also in tests so we don't
have to re-init and setup a node.

AI-assisted-by: OpenAI Codex
This was unimplemented for the postgres kv store. Useful if the user
wants to migrate to a different database and also in tests so we don't
have to re-init and setup a node.

AI-assisted-by: OpenAI Codex
Extract the existing obfuscated key selection so later VSS listing
changes can reuse it without changing the parsing behavior.

AI-assisted-by: OpenAI Codex
This was unimplemented for the VSS kv store. Useful if the user wants
to migrate to a different database and keeps VSS aligned with the other
persistent stores.

AI-assisted-by: OpenAI Codex
This was unimplemented for the in-memory kv store. Useful in tests so
we can migrate data across all supported store implementations.

AI-assisted-by: OpenAI Codex
Creates a node with LN and on-chain state and then randomly migrates
through all the KV store options and checks it still has its state.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
use lightning_persister::fs_store::v2::FilesystemStoreV2;
use rand::seq::SliceRandom;

async fn drop_tables<'a>(table_names: impl IntoIterator<Item = &'a String>) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need all this verbose boilerplate for the single test? Seems just choosing two backends at random could be only a few LoC inline?

Comment thread Cargo.toml

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["tokio"] }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need an extra dev-dependency now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants